<template>
  <div class="risk">
    <div
      class="add"
      @click="edit()"
    >新增设备设施</div>
    <eagle-tab-page-list
      url="/EquEquipment/GetPageData"
      :params="params"
      @initActive="_initActive"
      @initList="_initList"
      ref="eagleTabPageList"
    >
      <eagle-cell
        class="card"
        v-for="(item, index) in list"
        :key="index"
      >
        <template v-if="active===0">
          <div class="warn_item">
              <div @click="goDetail(item.EquipmentCode)">
                <div class="warn_header">
                  <div>{{ item.EquipmentName }}</div>
                  <eagle-tag
                    v-if="item.ExpireDays < 0"
                    class="warn_tag"
                    type="primary"
                  >剩{{ Math.abs(item.ExpireDays) }}天</eagle-tag>
                  <eagle-tag
                    v-if="item.ExpireDays > 0"
                    class="warn_tag"
                    type="danger"
                  >逾期{{ Math.abs(item.ExpireDays) }}天</eagle-tag>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_number.png"
                    alt=""
                  />
                  <div>编号：{{ item.EquipmentNo }}</div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_equ_type.png"
                    alt=""
                  />
                  <div>类型：{{ item.EquipmentTypeName }}</div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_group.png"
                    alt=""
                  />
                  <div>使用部门：{{ item.OrgName }}</div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />
                  <div>下次检验日期：{{ item.NextCheckDay || "无" }}</div>
                </div>
              </div>
              <eagle-divider />
              <div class="dep_btm">
                <div
                  v-if="item.IsNeedCheck"
                  class="btm_item"
                  @click="editCheck(item.EquipmentCode)"
                >
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-20">设备检验</div>
                </div>
                <div
                  class="btm_item"
                  @click="getFile(item.EquipmentCode)"
                >
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-20">安全附件</div>
                </div>
                <div
                  class="btm_item"
                  @click="edit(item.EquipmentCode)"
                >
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-10">编辑</div>
                </div>
              </div>
            </div>
        </template>
        <template v-else>
          <div class="warn_item">
              <div @click="goDetail(item.EquipmentCode)">
                <div class="warn_header">
                  <div>{{ item.EquipmentName }}</div>
                  <eagle-tag
                    v-if="item.ExpireDays < 0"
                    class="warn_tag"
                    type="primary"
                  >剩{{ Math.abs(item.ExpireDays) }}天</eagle-tag>
                  <eagle-tag
                    v-if="item.ExpireDays > 0"
                    class="warn_tag"
                    type="danger"
                  >逾期{{ Math.abs(item.ExpireDays) }}天</eagle-tag>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_number.png"
                    alt=""
                  />
                  <div>编号：{{ item.EquipmentNo }}</div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_equ_type.png"
                    alt=""
                  />
                  <div>类型：{{ item.EquipmentTypeName }}</div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_group.png"
                    alt=""
                  />
                  <div>使用部门：{{ item.OrgName }}</div>
                </div>
                <div class="dep_sort">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />
                  <div>下次检验日期：{{ item.NextCheckDay || "无" }}</div>
                </div>
              </div>

              <!-- <div class="dep_btm">
                <div class="btm_item" @click="getFile(item.EquipmentCode)">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-20">安全附件</div>
                </div>
                <div class="btm_item" @click="edit">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_edit.png"
                    alt=""
                  />
                  <div class="mr-10">编辑</div>
                </div>
              </div> -->
            </div>
        </template>
      </eagle-cell>
    </eagle-tab-page-list>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getDate } from "@/utils/getDate";
export default {
  data() {
    return {
      active: 0,
      list: [],
      params: [
        {
          title: "我管理的设备",
          dataType: "MyList",
        },
      ],
      editFlag: false,
    };
  },
  created() {
    
    if(this.roles.indexOf('depart') != -1){
      this.params.push({
        title: "我部门使用的设备",
        dataType: "DeptUsedList",
      })
    } 
  },
  computed: {
    ...mapGetters(["roles"]),
  },
  beforeRouteLeave(to, from, next) {
    if (to.path == "/Equipment/Edit") {
      if (this.editFlag) {
        to.meta.title = "编辑设备信息";
      } else {
        to.meta.title = "新增设备信息";
      }
    }
    next(); //继续下一步
  },
  methods: {
    _initActive(active) {
      this.active = active;
    },
    _initList(list) {
      this.list = list;
    },
    // 设备详情
    goDetail(equipmentCode) {
      this.$router.push({
        path: "/Equipment/Detail",
        query: { equipmentCode: equipmentCode },
      });
    },
    getFile(equipmentCode) {
      this.$router.push({
        path: "/Equipment/safetyfile",
        query: { equipmentCode: equipmentCode },
      });
    },
    // 编辑设备信息
    edit(equipmentCode) {
      if (equipmentCode) {
        this.editFlag = true;
      } else {
        this.editFlag = false;
      }
      console.log("asdasdasd", this.editFlag);
      this.$router.push({
        path: "/Equipment/Edit",
        query: { equipmentCode: equipmentCode },
      });
    },
    // 设备检验
    editCheck(equipmentCode) {
      this.$router.push({
        path: "/Equipment/editcheck",
        query: { equipmentCode: equipmentCode },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.all_dep {
  background-color: #ffffff;
}
.van-cell {
  padding: 0 0;
}
.warn_item {
  padding: 10px 10px;
  /*margin-bottom: 10px;*/

  border-radius: 5px;
  position: relative;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: -10px;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
